#ifndef __BUFFER_H__
#define __BUFFER_H__

#include    <thread/Shared.h>
#include    <thread/Mutex.h>
#include    <thread/Handle.h>

#include    <vector>
#include	<stdint.h>

namespace MyUtil
{
using namespace std;

class BufferDrainer : public IceUtil::Shared
{
public:
	virtual int drain(const string& data) = 0;	
};
typedef IceUtil::Handle<BufferDrainer> BufferDrainerPtr;

class Buffer : public IceUtil::Shared
{
public:
	Buffer() {
		_dataLength = 0;
	}
    string drain(const BufferDrainerPtr& drainer);
	string drain();
    
    void insert(const string& data);
    
    void append(const string& data);
    
    void append(const char* data, int length);
    
    void clear();

    int size();

//	int getDataLength();
private:
    string _data;
	uint32_t _dataLength ;
    IceUtil::Mutex _mutex;
};
typedef IceUtil::Handle<Buffer> BufferPtr;

}
#endif
